package com.sq.shortlink.admin.controller;

import com.sq.shortlink.admin.common.convension.result.Result;
import com.sq.shortlink.admin.common.convension.result.Results;
import com.sq.shortlink.admin.dto.req.*;
import com.sq.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短链接分组控制层
 * @author quan
 */
@RestController
@RequestMapping("/api/short-link/admin/v1/group")
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 新增短链接分组
     */
    @PostMapping
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupReqDTO requestParam){
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }

    /**
     * 查询短链接分组集合
     */
    @GetMapping
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }

    /**
     * 修改短链接分组名称
     */
    @PutMapping
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReq requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    /**
     * 删除短链接分组
     */
    @DeleteMapping
    public Result<Void> deleteGroup(@RequestBody ShortLinkGroupDeleteReq requestParam){
        groupService.deleteGroup(requestParam);
        return Results.success();
    }

    /**
     * 修改短链接分组排序
     */
    @PutMapping("/sort")
    public Result<Void> updateGroupOrder(@RequestBody List<ShortLinkGroupSortReq> requestParam){
        groupService.updateGroupSort(requestParam);
        return Results.success();
    }
}
